#ifndef TIMEDWIDGET_H
#define TIMEDWIDGET_H

#include <QWidget>
#include <QCheckBox>
#include <QRadioButton>
#include <QLabel>
#include <QSpinBox>
#include <QComboBox>
#include <QPushButton>
#include <QLineEdit>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QGroupBox>
#include "config/AppConfig.h"
#include "config/GlobalDefine.h"
#include "ConfigService.h"  // 使用ConfigService替代直接访问AppConfig
#include "FileLineEdit.h"

class TimedWidget : public QWidget
{
    Q_OBJECT
public:
    explicit TimedWidget(int nScreenWidth,int nScreenHeigth,QWidget *parent = nullptr);
    ~TimedWidget();
    void setFormSize(int nScreenWidth,int nScreenHeigth);
signals:
    void sigClose();
private:
    void setupForm();
    void initData();
    void saveData();

    void setTimeData(int time);
    int getTimeData();

    void setFontData();
    QFont getFontData();

    void setFormat();
    void getFormat();

    void setTimeOutAction();
    void getTimeOutAction();

    void setPlayback();
    void getPlayback();
private slots:
    void onSaveDataBtn();
    // 槽函数：更新 QLabel 显示的值
    void updateLabel(int value);
    void updateWarn1Spin(int value);
    void updateWarn2Spin(int value);
    void updateWarn3Spin(int value);

    void onTransparentChanged(int state);
    void onScreenBlackChanged(int state);
    void onScreenWhiteChanged(int state);
private:
    int m_nScreenWidth = 0,m_nScreenHeigth = 0;
    QCheckBox *cbTimerDuration;
    QSpinBox *sbHour;
    QSpinBox *sbMinute;
    QSpinBox *sbSecond;
    QRadioButton *rbCountdown;
    QRadioButton *rbCountup;

    QCheckBox *cbWarning1;
    QSpinBox *sbWarning1Time;
    QCheckBox *cbWarning2;
    QSpinBox *sbWarning2Time;
    QCheckBox *cbWarning3;
    QSpinBox *sbWarning3Time;
    QCheckBox *cbContinuousWarning;

    QCheckBox *cbOvertime;
    QSpinBox *sbOvertimeDuration;

    QRadioButton *rbFormat59Sec;
    QRadioButton *rbFormat59MinSec;
    QRadioButton *rbFormat23HoursMinSec;

    QRadioButton *rbOvertimeCount;
    QRadioButton *rbStopCount;
    QRadioButton *rbLoopCount;
    QCheckBox *cbTransparent;
    QCheckBox *cbScreenBlack;
    QCheckBox *cbScreenWhite;

    QCheckBox *cbSmartCount;
    QCheckBox *cbCountSettings;
    QCheckBox *cbPauseCount;
    QCheckBox *cbChangeTime;
    QCheckBox *cbHideClock;
    QCheckBox *cbShowOnSecondaryScreen;

    QComboBox *fontCombo;
    QComboBox *fontSizeCombo;
    QComboBox *colorCombo;
    QCheckBox *cbTransparentBackground;
    FileLineEdit *backgroundPath;
    QSpinBox *radiusSpinBox;

    QPushButton *btnSpecialCount;
    QPushButton *btnHelp;
    QPushButton *btnApply;
    QPushButton *btnClose;
private:
    QFont m_font;
    TimerConfig m_timerConfig;  // Store TimerConfig
    TimeoutAction m_timeoutAction;  // Store TimeoutAction instance
    PlaybackSettings m_playbackSettings;
    BackgroundSettings m_bgSettings;
    TimeFormat m_timeFormat;
};

#endif // TIMEDWIDGET_H
